#
# file: footer.mk
#
# author: Copyright (C) 2015-2016 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
#
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
# distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

#-----------------------------------------------------------------------------------------------------------------------
# source files (only if not provided by parent Rules.mk)
#-----------------------------------------------------------------------------------------------------------------------

ASSOURCES_$(d) ?= $(wildcard $(d)*.S)
CSOURCES_$(d) ?= $(wildcard $(d)*.c)
CXXSOURCES_$(d) ?= $(wildcard $(d)*.cpp)

#-----------------------------------------------------------------------------------------------------------------------
# paths and names of object and dependency files
#-----------------------------------------------------------------------------------------------------------------------

ASOBJECTS_$(d) := $(ASSOURCES_$(d):%.S=$(OUTPUT)%.o)
COBJECTS_$(d) := $(CSOURCES_$(d):%.c=$(OUTPUT)%.o)
CXXOBJECTS_$(d) := $(CXXSOURCES_$(d):%.cpp=$(OUTPUT)%.o)
OBJECTS_$(d) := $(ASOBJECTS_$(d)) $(COBJECTS_$(d)) $(CXXOBJECTS_$(d))
DEPENDENCIES_$(d) := $(OBJECTS_$(d):%.o=%.d)

#-----------------------------------------------------------------------------------------------------------------------
# add local files to global rules
#-----------------------------------------------------------------------------------------------------------------------

OBJECTS := $(OBJECTS) $(OBJECTS_$(d))
GENERATED := $(GENERATED) $(OBJECTS_$(d)) $(DEPENDENCIES_$(d))

#-----------------------------------------------------------------------------------------------------------------------
# generated files depend on local Rules.mk and global footer.mk
#-----------------------------------------------------------------------------------------------------------------------

$(OBJECTS_$(d)): $(d)Rules.mk $(DISTORTOS_PATH)footer.mk

#-----------------------------------------------------------------------------------------------------------------------
# set compilation flags
#-----------------------------------------------------------------------------------------------------------------------

$(ASOBJECTS_$(d)): ASFLAGS := $(ASFLAGS) $(ASFLAGS_$(d))
$(COBJECTS_$(d)): CFLAGS := $(CFLAGS) $(CFLAGS_$(d))
$(CXXOBJECTS_$(d)): CXXFLAGS := $(CXXFLAGS) $(CXXFLAGS_$(d))

#-----------------------------------------------------------------------------------------------------------------------
# include generated dependency files
#-----------------------------------------------------------------------------------------------------------------------

-include $(DEPENDENCIES_$(d))

#-----------------------------------------------------------------------------------------------------------------------
# doxygen exclusions
#-----------------------------------------------------------------------------------------------------------------------

DOXYGEN_EXCLUDE := $(DOXYGEN_EXCLUDE) $(patsubst %,$(d)%/,$(SUBDIRECTORIES))
DOXYGEN_EXCLUDE := $(filter-out %$(d),$(DOXYGEN_EXCLUDE))

#-----------------------------------------------------------------------------------------------------------------------
# parse Rules.mk files lower in the hierarchy
#-----------------------------------------------------------------------------------------------------------------------

SAVED_GENERATED_$(d) := $(GENERATED)
SAVED_OBJECTS_$(d) := $(OBJECTS)

$(call PARSE_SUBDIRECTORIES,$(SUBDIRECTORIES))

# list of generated files by all $(SUBDIRECTORIES)
SUBDIRECTORIES_GENERATED_$(d) := $(filter-out $(SAVED_GENERATED_$(d)),$(GENERATED))

# list of object files generated by all $(SUBDIRECTORIES)
SUBDIRECTORIES_OBJECTS_$(d) := $(filter-out $(SAVED_OBJECTS_$(d)),$(OBJECTS))

#-----------------------------------------------------------------------------------------------------------------------
# files generated by all $(SUBDIRECTORIES) depend on local Rules.mk
#-----------------------------------------------------------------------------------------------------------------------

$(SUBDIRECTORIES_GENERATED_$(d)): $(d)Rules.mk
